package io.datajek.springbasics.movierecommendersystem.lesson11;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

//推荐电影方法的逻辑
//将过滤器的类型从基于内容改为协作式
//CollaborativeFilter-协同式过滤
@Component
public class RecommenderImplementation {

    private Logger logger =
            LoggerFactory.getLogger(this.getClass());

    @Autowired
    @Qualifier("CABF")
    private Filter filter;

//    public RecommenderImplementation(Filter filter) {
//        this.contentBasedFilter = filter;
//    }


    public void setFilter(Filter filter) {
        logger.info("In RecommenderImplementation setter method..dependency injection");
        this.filter = filter;
    }

    public String[] recommendMovies (String movie) {

        //使用ContentBasedFilter来寻找类似的电影
//        CollaborativeFilter filter = new CollaborativeFilter();
        //上面的语句的filter不需要重新定义了
        //此处的输入参数暂时无用
        String[] results = filter.getRecommendations("Finding Dory");
        //返回结果
        return results;
    }

    public void postConstruct() {
        //初始化代码放这里
        logger.info("In RecommenderImplementation postConstruct method");
    }

    @PreDestroy
    public void preDestroy() {
        //用于清理的代码
        logger.info("In RecommenderImplementation preDestroy method");
    }



}
